package com.dyzx.hbb.modules.car.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dyzx.hbb.common.config.MyLambdaQueryWrapper;
import com.dyzx.hbb.modules.car.entity.CarModelArea;
import com.dyzx.hbb.modules.car.service.CarModelAreaService;
import com.dyzx.hbb.modules.car.mapper.CarModelAreaMapper;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author Administrator
* @description 针对表【car_model_area】的数据库操作Service实现
* @createDate 2025-08-08 13:19:02
*/
@Service
public class CarModelAreaServiceImpl extends ServiceImpl<CarModelAreaMapper, CarModelArea>
    implements CarModelAreaService{
    @Cacheable(value = "car", key = "'tree::modal::area'+#modelId")
    @Override
    public List<Map<String, Object>> findByTreeList(Long modelId) {
        List<Map<String, Object>> results=new ArrayList<>();
        MyLambdaQueryWrapper<CarModelArea> queryWrapper = new MyLambdaQueryWrapper<>();
        queryWrapper.eq(CarModelArea::getModelId,modelId);

        List<CarModelArea> list=this.list(queryWrapper);
        for (CarModelArea carModelArea : list) {
            Map<String, Object> map=new HashMap<>() ;
            map.put("id",carModelArea.getId());
            map.put("name",carModelArea.getName());
            map.put("modal_id",carModelArea.getModelId());
            map.put("trans_mission",carModelArea.getTransMission());
            map.put("drive_mode_name",carModelArea.getDriveModeName());
            map.put("year",carModelArea.getYear());
            map.put("min_price",carModelArea.getMinPrice());
            map.put("max_price",carModelArea.getMaxPrice());
            results.add(map);
        }
        return results;
    }
}




